package com.css.fxfzmhwz.base.dict;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.css.fxfzmhwz.base.dict.repository.entity.DictItemEntity;
import com.css.fxfzmhwz.base.dict.service.DictItemService;
import com.css.fxfzmhwz.base.dict.viewobjects.DictItemExcelVO;
import com.css.fxfzmhwz.util.PlatformObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author chenjun
 * @Date 2020/4/26
 * @Description
 */

@Component
public class DictItemExcelVerifyHandler implements IExcelVerifyHandler<DictItemExcelVO> {

    @Autowired
    DictItemService dictItemService;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(DictItemExcelVO dictExcelVo) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        StringBuffer message = new StringBuffer("");

        DictItemEntity dictItemEntity = dictItemService.getDictItem(dictExcelVo.getDictId());
        if(!PlatformObjectUtils.isEmpty(dictItemEntity)){
            result.setSuccess(false);
            message.append("字典项"+dictExcelVo.getDictItemName()+"已存在");
        }
        result.setMsg(message.toString());
        return result;
    }
}
